// pages/home/home.js
let app = getApp();
var that;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navRightItems: [],
    autoplay: false,
    // interval: 5000,
    duration: 1000,
    circular: true,
    jpshoplist: [],
    likeshoplist: [],
    loadingHidden: false,
    page: 1,
    limit: 10,
    banner: []
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    that  = this
    app.getData({
      url: app.api.getIndexBanner() + `?shopId=${wx.getStorageSync('shopData').id}&page=1&rows=3&adCategory=2`,
      method: 'GET',
      ok: function (res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            that.setData({
              banner: res.data.list,
            });
            // this.tab_config = res.data.data

          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    that = this
    that.getshopSele()
    that.getshopLike()
  },
  getshopSele() {
    app.getData({
      url: app.api.getShopSele(),
      method: "POST",
      data: {
        page: that.data.page,
        limit: that.data.limit,
        companyId: app.globalData.shopData.companyId
      },

      ok: function(res) {

        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            setTimeout(function() {
              that.setData({
                loadingHidden: true,
                jpshoplist: res.data.list
              })
            }, 500)
          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        }
      }
    })

  },
  getshopLike() {
    app.getData({
      url: app.api.getshopLike(),
      method: "POST",
      data: {
        page: that.data.page,
        limit: that.data.limit,
        companyId: app.globalData.shopData.companyId
      },

      ok: function(res) {

        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            setTimeout(function() {
              that.setData({
                likeshoplist: res.data.data
              })
            }, 500)
          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        }
      }
    })

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  //小程序触底方法
  onReachBottom: function (res) {
    if (that.data.isLoadMore) {
      that.getshopLike() 
    } else {
      that.setData({
        isJzwb: true,
        isJzz: true
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})